﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using TeamRobin.BattleCity.Core.Utils;

namespace TeamRobin.BattleCity.Core.ScreenText
{
	public class GameScreen
	{
		private static int sleepdelay = 50;
		private static string logo = File.ReadAllText(@"..\..\Content\TextArt\logo.txt");

		public static void SetScreen()
		{
			Console.WindowHeight = 54;
			Console.BufferHeight = 54;
			Console.WindowWidth = 115;
			Console.BufferWidth = 115;
		}

		public static void SetLevelScreen()
		{
			Console.WindowHeight = 44;
			Console.BufferHeight = 44;
			Console.WindowWidth = 66;
			Console.BufferWidth = 66;
		}

		private static void PrintLogo()
		{
			foreach (var item in logo)
			{
				if (item != '\n')
				{
					if (item == 'M')
					{
						Console.ForegroundColor = ConsoleColor.Black;
					}
					else
					{
						Console.ForegroundColor = ConsoleColor.Red;
					}
					Console.Write(item);
				}
			}
		}

		private static void PrintLogoAnimated()
		{
			List<char> row = new List<char>();
			foreach (var item in logo)
			{
				if (item == '\n')
				{
					foreach (var symbol in row)
					{
						if (symbol == 'M')
						{
							Console.ForegroundColor = ConsoleColor.Black;
						}
						else
						{
							Console.ForegroundColor = ConsoleColor.Red;
						}
						Console.Write(symbol);
					}
					Thread.Sleep(sleepdelay);
					row.Clear();
				}
				else
				{
					row.Add(item);
				}
			}
		}

		public static void BattleCity()
		{
			SetScreen();
			Sounds.NewGameLevelSound();

			#region PrintLogo

			Console.Clear();
			PrintLogoAnimated();

			#endregion PrintLogo

			Thread.Sleep(sleepdelay);

			#region PRESS ANY KEY

			for (int i = 50; i > 24; i = i - 2)
			{
				Console.ForegroundColor = ConsoleColor.Black;
				Console.SetCursorPosition(47, i + 2);
				Console.WriteLine("PRESS ANY KEY TO START");

				Console.ForegroundColor = ConsoleColor.Red;
				Console.SetCursorPosition(47, i);
				Console.WriteLine("PRESS ANY KEY TO START");

				Thread.Sleep(sleepdelay);
			}

			#endregion PRESS ANY KEY

			#region 1 Player Mode

			for (int i = 50; i > 26; i = i - 2)
			{
				Console.ForegroundColor = ConsoleColor.Black;
				Console.SetCursorPosition(47, i + 2);
				Console.WriteLine("1 Player Mode");

				Console.ForegroundColor = ConsoleColor.White;
				Console.SetCursorPosition(47, i);
				Console.WriteLine("1 Player Mode");

				Thread.Sleep(sleepdelay);
			}

			#endregion 1 Player Mode

			#region 2 Player Mode

			for (int i = 50; i > 28; i = i - 2)
			{
				Console.ForegroundColor = ConsoleColor.Black;
				Console.SetCursorPosition(47, i + 2);
				Console.WriteLine("2 Player Mode (Comming Soon)");

				Console.ForegroundColor = ConsoleColor.DarkGray;
				Console.SetCursorPosition(47, i);
				Console.WriteLine("2 Player Mode (Comming Soon)");
				Console.ForegroundColor = ConsoleColor.White;

				Thread.Sleep(sleepdelay);
			}
			Console.ForegroundColor = ConsoleColor.DarkGray;
			Console.SetCursorPosition(47, 30);
			Console.WriteLine("2 Player Mode (Comming Soon)");
			Console.ForegroundColor = ConsoleColor.White;

			#endregion 2 Player Mode

			Console.ReadKey(true);
		}
	}
}